package com.example.spareparts.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.spareparts.entity.SpareCategory;
import com.example.spareparts.service.SpareCategoryService;
import java.util.List;



@RestController
@RequestMapping("/api/sparecategories")
public class SpareCategoryController {
    @Autowired
    private SpareCategoryService spareCategoryService;
    @GetMapping ("/listall")
    public List<SpareCategory> findAllSpareCategory(){
        return spareCategoryService.findAllSpareCategory();
    }
    @PostMapping ("/insert")
    public void insertSpareCategory(@RequestBody SpareCategory spareCategory){
        spareCategoryService.insertSpareCategory(spareCategory);

    }
    @PutMapping ("/update/{categoryid}")
    public void updateSpareCategory(@PathVariable Long categoryid, @RequestBody SpareCategory spareCategory){
        spareCategory.setCategoryid(categoryid);
        spareCategoryService.updateSpareCategory(spareCategory);
    }
    @DeleteMapping ("/delete/{categoryid}")
    public void deleteSpareCategory(@PathVariable Long categoryid){
        spareCategoryService.deleteSpareCategory(categoryid);
    }
    @GetMapping ("/findbyid/{categoryid}")
    public SpareCategory findSpareCategoryById(@PathVariable Long categoryid){
        return spareCategoryService.findSpareCategoryById(categoryid);
    }
    @GetMapping ("/findbysparepartid/{sparepartid}")
    public List<SpareCategory> findSpareCategoryBySparePartId(@PathVariable Long sparepartid){
        return spareCategoryService.findSpareCategoryBySparePartId(sparepartid);
    }
}
